/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cn.ccp.listener;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class TimeUtils {

    public static String getLongTime(final Date date) {
        if (date == null) {
            return null;
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String result = "";
        result = df.format(date);
        return result;
    }

    public static String getShortTime(final Date date) {
        if (date == null) {
            return null;
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String result = "";
        result = df.format(date);
        return result;
    }

    public static Date getDate(String sDate) {
        if (sDate == null) {
            return null;
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = df.parse(sDate);
        } catch (ParseException ex) {
            Logger.getLogger(TimeUtils.class.getName()).log(Level.SEVERE, null, ex);
        }
        return date;
    }

}
